package logic

import (
	"context"
	"sport/models/mysql"

	"sport/sportrpc/internal/svc"
	"sport/sportrpc/sportrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PostShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPostShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostShowLogic {
	return &PostShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 帖子详情
func (l *PostShowLogic) PostShow(in *sportrpc.PostShowRequest) (*sportrpc.PostShowHotResponse, error) {
	// todo: add your logic here and delete this line
	var post mysql.Post
	mysql.DB.Where("id = ?", in.Id).Find(&post)
	return &sportrpc.PostShowHotResponse{
		Id:      int64(post.ID),
		UserId:  int64(post.UserId),
		ForumId: int64(post.ForumId),
		Title:   post.Title,
		Content: post.Content,
		Liked:   int64(post.Liked),
	}, nil
}
